class utils {
	constructor() {
		this.baseUrl = "http://159.75.169.224:7300/pz"
	}
	getuserInfo() {
		uni.login({
			success: (res) => {
				this.request({
					url: '/auth/wxLogin',
					data: {
						code: res.code
					},
					success: (res) => {
						console.log(res);
					}
				})
			}
		})
	}
	request(options = {
		showLoading: false
	}) {
		if (!options.url) {
			return
		}
		if (options.showLoading) {
			this.showLoading()
		}
		uni.request({
			url: this.baseUrl + options.url,
			data: options.data ? options.data : {},
			header: options.header ? options.header : {},
			method: options.method ? options.method : "GET",
			success: (response) => {
				uni.hideLoading()
				if (response.data.code == 10000) {
					if (options.success && typeof options.success == "function") {
						options.success(response.data)
					}
				} else {
					if (options.fail && typeof options.fail == "function") {
						options.fail(response.data)
					}
				}
			},
			fail: response => {
				console.log(response.data);
			}

		})
	}
	showLoading() {
		const isShowLoading = uni.getStorageSync("isShowLoading")
		if (isShowLoading) {
			uni.hideLoading()
			uni.setStorageSync("isShowLoading", false)
		}
		uni.showLoading({
			title: '加载中。。。',
			complete: function() {
				uni.setStorageSync("isShowLoading", true)
			},
			fail: function() {
				uni.setStorageSync("isShowLoading", false)
			}
		})
	}
}
export default new utils()